dojo.declare("MVendorProductCatalogsPg", wm.Page, {
    start: function() {
        var mainPage = wm.Page.getPage("MobileMainPg");

        this.lvMenuItems.filter.setValue("customer.customerId", mainPage.vUserId);

        this.lvMenuItems.update(); 
 
    },
    "preferredDevice": "phone",

    itemsDojoGridImageUrlFormat: function(inValue, rowId, cellId, cellField, cellObj, rowObj) {
        try {
            var file = "services/FileUploadDownload.download?method=downloadFile&fileName=" + inValue;
            return '<img  style="height: 50px;" src="' + inValue + '" />';
        } catch (e) {
            console.error('ERROR IN dojoGrid2PicurlFormat: ' + e);
        }
    },
    itemsDojoGridItemIdFormat: function(inValue, rowId, cellId, cellField, cellObj, rowObj) {
        var currency = "";
        if (rowObj.currency && rowObj.currency !== null) {
            currency = rowObj.currency;
        }
        var display = "<div class='MobileRowTitle'>ItemName: " + rowObj.itemName + "</div>" + "<div class='MobileRow'>ItemDesc: " + rowObj.itemDesc + "</div>" + "<div class='MobileRow'>Base Price:" +currency+ " " + rowObj.baseValue + "</div>" + "</div>" + "<div class='MobileRow'>Total Price:"+currency+ " " + rowObj.price  + "</div>";
        var outOfStock = "No";
        if (rowObj.outOfStock) {
            outOfStock = "Yes";
        }


        display = display + "<div class='MobileRow'>OutOfStock: " + outOfStock + "</div>";
        // display = display + "<div class='MobileRow'>Is Active: " + rowObj.active + "</div>";
        return display;
    },

    calculateFinalPrice: function() {

        var itemObj = this.itemsDojoGrid.selectedItem.getItem(this.itemsDojoGrid.getSelectedIndex()).data;
        var vatPercent = itemObj.vat;
        var eduCess = itemObj.eduCess;
        var serviceTax = itemObj.serviceTax;
        var serviceCharge = itemObj.serviceCharge;
        var tpsPercInc = itemObj.tpsPercentIncl;
        var tpsPerExcl = itemObj.tpsPercentExl;
        var tpsShareInc = itemObj.tpsShareIncl;
        var tpsShareExcl = itemObj.tpsShareExl;
        var basePrice = this.priceEditor2.getDataValue();
        var finalPrice = 0;

        /**  console.error('vatPercent=' + vatPercent);
         console.error('serviceTax=' + serviceTax);
         console.error('tpsPercInc=' + tpsPercInc);
         console.error('tpsPerExcl=' + tpsPerExcl);
         console.error('tpsShareInc=' + tpsShareInc);
         console.error('tpsShareExcl=' + tpsShareExcl);
         
         console.error('basePrice=' + basePrice); **/


        if (vatPercent !== 0) {

            finalPrice = finalPrice + ((vatPercent / 100) * basePrice);

            if (eduCess !== 0) {
                var eduCessPercent = vatPercent / eduCess;
                finalPrice = finalPrice + (eduCessPercent / 100) * basePrice;
            }

        }
        if (serviceTax !== 0) {
            finalPrice = finalPrice + (serviceTax / 100) * basePrice;
        }
        if (serviceCharge !== 0) {
            finalPrice = finalPrice + (serviceCharge / 100) * basePrice;
        }
        if (tpsPerExcl !== 0) {

            finalPrice = finalPrice + (tpsPerExcl / 100) * basePrice;
        }

        else if (tpsShareExcl !== 0) {
            tpsShareExcl = tpsShareExcl / 1;
            finalPrice = finalPrice + tpsShareExcl;
        }

        basePrice = basePrice / 1;
        finalPrice = finalPrice + basePrice; /* */

        this.finalPriceEditor.setDataValue(finalPrice);


    },

    itemsSaveButton1Click: function(inSender) {
        this.calculateFinalPrice();
        this.itemsLiveForm2.saveDataIfValid();
        
    },
    priceEditor2Change: function(inSender, inDisplayValue, inDataValue, inSetByCode) {
		this.calculateFinalPrice();
	},
	itemsCancelButton1Click2: function(inSender) {
		//this.itemsDojoGrid.deselectAll();
	},
	itemsDialog1Close: function(inSender, inWhy) {
		    this.itemsDojoGrid.deselectAll();
	},
	_end: 0
});